/// Includes system
#include <cstdio>
#include <cstdlib>
/// Includes projects
#include "../common/framework.h"
#include "../common/deviceSelect.h"
#include "svmTrain.h"
#include "svmTrainConfig.h"
#include "svmTrainData.h"

int main( const int argc, const char** argv)  {
	printf("%s Starting...\n",argv[0]);
	int devID = chooseLargestGPU(true);

	svmTrainConfig* config = new svmTrainConfig();
	svmTrainData* trainingData = new svmTrainData();
	svmTrain* smo = new svmTrain(config, trainingData);

	/// parse command
	config->parseCommand(argc,argv);
	/// read training data
	trainingData->readSvm(config->trainingFilename);

	trainingData->genOACode();
	//return 0;
	/// evaluate parameters
	config->checkParam(trainingData->nDimension);
	/// start training
	switch(config->kType) {
		case GAUSSIAN:
			smo->train<GAUSSIAN>(); break;
		case LINEAR:
			smo->train<LINEAR>(); break;
		case POLYNOMIAL:
			smo->train<POLYNOMIAL>(); break;
		case SIGMOID:
			smo->train<SIGMOID>(); break;
	}
	/// write model file
	smo->printModel();
	/// clean training result (Alpha)
	smo->cleanTrainingResult();

	/// clean training data
	trainingData->cleanData();
	delete smo;
	delete config;
	delete trainingData;
	//system("PAUSE");
	return 0;
}